#pragma once

#ifdef WGLENGINE_DLL
#define WGLENGINE_EXPORT __declspec(dllexport)
#else
#define WGLENGINE_EXPORT __declspec(dllimport)
#endif

#include "GL\glew.h"
#include "glm\glm.hpp"

#include "Material.h"
#include "SceneMesh.h"
#include "SceneNode.h"

#include <vector>

class WGLENGINE_EXPORT WCube : public SceneMesh
{
protected:
	virtual void RenderMesh(int pass) override
	{
		std::shared_ptr<Shader> shader = mat->GetShader();
		mat->Bind();
		glBindVertexArray(vaoID);
		glDrawArrays(GL_TRIANGLES, 0, 36);
		glBindVertexArray(0);
		mat->Unbind();
	}

public:
	WCube(std::string material = "")
		: SceneMesh(material)
	{
		meshType = MeshData::POSITION;
	}

	~WCube()
	{

	}

	virtual void GenVBO() override
	{
		float points[] = {
						  -1.0f,  1.0f, -1.0f,
						  -1.0f, -1.0f, -1.0f,
						   1.0f, -1.0f, -1.0f,
						   1.0f, -1.0f, -1.0f,
						   1.0f,  1.0f, -1.0f,
						  -1.0f,  1.0f, -1.0f,
  
						  -1.0f, -1.0f,  1.0f,
						  -1.0f, -1.0f, -1.0f,
						  -1.0f,  1.0f, -1.0f,
						  -1.0f,  1.0f, -1.0f,
						  -1.0f,  1.0f,  1.0f,
						  -1.0f, -1.0f,  1.0f,
  
						   1.0f, -1.0f, -1.0f,
						   1.0f, -1.0f,  1.0f,
						   1.0f,  1.0f,  1.0f,
						   1.0f,  1.0f,  1.0f,
						   1.0f,  1.0f, -1.0f,
						   1.0f, -1.0f, -1.0f,
   
						  -1.0f, -1.0f,  1.0f,
						  -1.0f,  1.0f,  1.0f,
						   1.0f,  1.0f,  1.0f,
						   1.0f,  1.0f,  1.0f,
						   1.0f, -1.0f,  1.0f,
						  -1.0f, -1.0f,  1.0f,
  
						  -1.0f,  1.0f, -1.0f,
						   1.0f,  1.0f, -1.0f,
						   1.0f,  1.0f,  1.0f,
						   1.0f,  1.0f,  1.0f,
						  -1.0f,  1.0f,  1.0f,
						  -1.0f,  1.0f, -1.0f,
  
						  -1.0f, -1.0f, -1.0f,
						  -1.0f, -1.0f,  1.0f,
						   1.0f, -1.0f, -1.0f,
						   1.0f, -1.0f, -1.0f,
						  -1.0f, -1.0f,  1.0f,
						   1.0f, -1.0f,  1.0f
						};

		CreateVertexArray(36);
		for(int i=0; i<108; i++)
		{
			SetVertexArray(i, points[i]);
		}
		
		vboIDs = std::unique_ptr<GLuint[]>(new GLuint[1]);

		glGenVertexArrays(1, &vaoID);
		glBindVertexArray(vaoID);

		glGenBuffers(1, vboIDs.get());

		glEnableVertexAttribArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, vboIDs[0]);
		glBufferData(GL_ARRAY_BUFFER, 36 * 3 * sizeof(GL_FLOAT), vertexPosArray.get(), GL_STATIC_DRAW);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *) nullptr);
	
		glBindVertexArray(0);
		initiated = true;
	}
};
